var websocket = null;
if("WebSocket" in window){
    websocket = new WebSocket("ws://192.168.40.23:8080/customWebSocket");
}else{
    alert("该浏览器不支持websocket");
}

websocket.onopen = function (evnet) {
    console.log("建立连接");
}

websocket.onclose = function (evnet) {
    console.log("连接关闭")
}

websocket.onmessage=function (evnet) {
    console.log("收到消息:"+evnet.data);
    var obj = eval('('+ evnet.data +')');
    if (obj.code == 101){
        $.ajax({
            url:"/cinemaInfo/select",
            type:"post",
            success:function (data) {
                var copyright = data.result.copyright;
                if (copyright.indexOf(obj.result.cname)!=-1){
                    layer.alert("套餐将于"+obj.result.overTime+"到期，请及时续费！");
                }
            }
        });
    }
    if (obj.code == 102){
        console.log(obj.result);
        $.ajax({
            url:"/cinemaInfo/updatePackage",
            data:{
                'str':obj.result
            },
            success:function (data) {
                if (data.code == 200){
                    layer.alert("套餐已更改，请及时查看");
                }
            }

        });
    }

}

websocket.onerror = function () {
    alert("websocket通信发生错误 ！");
}
